<template>
  <div class="container">
    <el-page-header @back="goBack" content="见证取样记录（标养）">
    </el-page-header>

    <div class="search">
      <span style="line-height: 100%">工程名称：</span>
      <el-input v-model="projectName" placeholder="请输入内容" style="width: 300px"/>
      <span style="line-height: 100%; margin-left: 10px">规格</span>
      <el-input v-model="subprojectName" placeholder="请输入内容" style="width: 300px"/>
      <span style="line-height: 100%; margin-left: 10px">取样部位：</span>
      <el-input v-model="usePart" placeholder="请输入内容" style="width: 300px"/>
      <el-button type="primary" style="margin-left: 10px;margin-right: 10px" @click="search">搜索</el-button>
      <el-button type="warning" style="margin-left: 10px;margin-right: 10px;" @click="batchExport">批量导出</el-button>
    </div>

    <el-table :data="currentPageData" stripe style="width: 100%; margin-top: 15px"
              @selection-change="handleSelectionChange" row-key="taskId" ref="tableRef"
    >
      <!-- 第一列：多选框 -->
      <el-table-column type="selection" width="55" :reserve-selection="true"/>
      <!-- 第二列：编号 -->
      <el-table-column prop="projectName" label="工程名称" width="250" align="center"/>
      <el-table-column prop="subprojectName" label="样品名称及规格" width="250" align="center"/>
      <el-table-column prop="usePart" label="取样部位" width="300" align="center"/>
      <el-table-column prop="level" label="批量" width="200" align="center"/>
      <el-table-column prop="yangHu" label="数量" width="100" align="center"/>
      <el-table-column prop="number" label="日期（取样）" width="150" align="center"/>
      <el-table-column prop="isFinished" label="委托编号" width="150" align="center"/>


      <!-- 最后一列：操作按钮 -->
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="handlePreview(scope.row)">
            预览
          </el-button>
          <el-button type="warning" @click="handleExport(scope.row)">
            导出
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 这是分页条  -->
    <el-pagination style="margin-top: 20px; text-align: center" :current-page="currentPage"
                   :page-sizes="[1, 10, 15, 20]" :page-size="pageSize" layout="prev, pager, next, jumper,->,sizes,total"
                   :total="totalData" @size-change="handleSizeChange" @current-change="handleCurrentChange"
    />

  </div>
</template>

<script>
import { searchFenbuCheck } from '@/api/statementManage/yanShou/statementManage'

export default {
  data() {
    return {
      projectName: '',
      subprojectName: '',
      usePart: '',     //这三个用来搜素表格项
      currentPageData: [],  //当前页面数据
      currentPage: 1,
      pageSize: 10,
      totalData: 0,   //这三个是分页条数据
      selectedRows: []  //选中行数组
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    handleSizeChange(val) {
      this.pageSize = val
      console.log('表格容量更新为：' + val)
      this.search()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log('表格页数更新为：' + val)
      this.search()
    },
    handlePreview(row) {
      console.log('预览表格行数据为：' + JSON.stringify(row))

      const keyData = {
        subprojectId: row.subprojectId,
        fenbuId: row.fenbuId
      }

      console.log(JSON.stringify(keyData))

      sessionStorage.setItem('tempObj1', JSON.stringify(keyData))

    },
    handleExport(row) {
      console.log('导出表格行数据为：' + JSON.stringify(row))
    },
    handleSelectionChange(val) {
      this.selectedRows = val
      console.log('当前选中行为：' + JSON.stringify(val))
    },
    async search() {
      console.log('进行了搜索，参数为：' + this.projectName + '  ' + this.subprojectName + '  ' + this.fenbuName)
      const { result } = await searchFenbuCheck(this.projectName, this.subprojectName, this.fenbuName, this.currentPage, this.pageSize)
      console.log(JSON.stringify(result))
      this.currentPageData = result.list
      this.totalData = Number(result.total)
    },
    batchExport() {
      console.log('进行了批量导出')
    }
  },
  mounted() {
    this.search()
  }
}
</script>

<style scoped>
.container {
  margin-top: 10px;
  margin-left: 10px;
}

.search {
  text-align: right;
  margin-top: 20px;
}
</style>
